package main

import (
	"fmt"
	"reflect"
)

type Rectangle struct {
	W float64	"width of the rectangle"
	H float64	"height of the rectangle"
}

func (r Rectangle) Area() float64 { return r.W*r.H }
func (r Rectangle) Perimeter() float64 { return 2*(r.W + r.H) }

func main() {
	v:=Rectangle{10,20}
	rValue:=reflect.ValueOf(&v).Elem()
	rType:=rValue.Type()

	fmt.Println(rType.NumField())
	for i:=0; i< rType.NumField(); i++ {
		fmt.Printf("%+v\n", rType.Field(i))
		tag:=rType.Field(i).Tag.Get("format")
		fmt.Printf("%[1]T %[1]+v\n", tag)
	}

	fmt.Println()

	fmt.Println(rValue.NumField())
	for i:=0; i< rValue.NumField(); i++ {
		rValue.Field(i).SetFloat(100.0)
		fmt.Printf("%+v\n", rValue.Field(i))
	}

	fmt.Println()
	fmt.Println(rValue.NumMethod())
	for i:=0; i< rValue.NumMethod(); i++ {
		fmt.Printf("%+v\n", rValue.Method(i).Call(nil)[0])
	}

}
